/*
 * @Author: your name
 * @Date: 2021-01-26 10:03:19
 * @LastEditTime: 2021-03-01 08:41:50
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \coordination\src\router\index.js
 */
import Vue from 'vue'
import store from '../store'
import VueRouter from 'vue-router'
import constants from "@/util/constants";
import horizontal from "./modules/horizontal";
import vertical from "./modules/vertical";
import axios from 'axios'; // 引入axios
Vue.use(VueRouter)
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    name: 'index',
    redirect: '/vertical',
  },
  horizontal,
  vertical,
  {
    path: '/login',
    component: () => import('@/views/login.vue'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
// 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]
const router = new VueRouter({
  // mode: 'history',
  // base: '/company/',
  // base: process.env.BASE_URL,
  // hashbang: false,
  routes
})





router.beforeEach((to, from, next) => {
  const {$getQueryString,$http,$message} = Vue.prototype
  const {storageInfo} = constants
  if(to.path==='/login'||sessionStorage.getItem(storageInfo.token)==="true"){
    next()
  }else {
    next('/login')
  }
  // if(true){
  //
  // }
  // next()
  // if(store.getters.token){
  //   next()
  // }else if(!store.state.setting.isLogin){
  //   next()
  // } else{
  //   const [token,card] = [$getQueryString("token"),$getQueryString("card")]
  //   store.commit('SET_TOKEN',token)
  //   store.commit('SET_CARD',card)
  //   if(sessionStorage.getItem(storageInfo.token)===token){
  //     const [chn,photoURL] = [sessionStorage.getItem(storageInfo.chn),sessionStorage.getItem(storageInfo.photoURL)]
  //     store.commit('SET_CHN',chn)
  //     store.commit('SET_PHOTO_URL',photoURL)
  //     next()
  //   }else{
  //     axios.get("http://10.6.1.198:8888/shiro/web/authc/address", {params:{user: card}}).then(res => {
  //       res = res.data.obj
  //       sessionStorage.setItem(storageInfo.token,token)
  //       sessionStorage.setItem(storageInfo.card,card)
  //       sessionStorage.setItem(storageInfo.chn,res.chn)
  //       sessionStorage.setItem(storageInfo.photoURL,res.photoURL)
  //       store.commit('SET_PHOTO_URL',res.photoURL)
  //       store.commit('SET_CHN',res.chn)
  //       next()
  //     }).catch((err) => {
  //       $message.error(err)
  //     });
  //   }
  // }
});
export default router
